package com.parking.mgr.useraccount.controller;

import com.parking.mgr.common.annotion.BusinessLog;
import com.parking.mgr.common.pojo.response.Result;
import com.parking.mgr.useraccount.service.UserIdFileCosService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @ClassName UserIdFileCosController
 * @Description TODO
 * @author: puyunqing
 * @Date: 2025/3/5
 */
@Log4j2
@Api(value = "用户身份证上传", tags = {"用户身份证上传"})
@RequestMapping("/api/user/id/")
@RestController
public class UserIdFileCosController {

    @Resource
    private UserIdFileCosService userIdFileCosService;

    @PostMapping("/front/uploadFile")
    @ApiOperation(value = "上传用户身份证正面", notes = "上传用户身份证正面", httpMethod = "POST")
    @BusinessLog(title = "上传用户身份证正面")
    public Result<?> uploadFrontFile(@RequestParam("file") MultipartFile file,
                                @ApiParam(name = "fTrueName", value = "真实姓名")
                                @RequestParam(value = "fTrueName", required = false) String fTrueName,
                                @ApiParam(name = "idNumber", value = "身份证号")
                                    @RequestParam(value = "idNumber", required = false) String idNumber,
                                HttpServletRequest request) {
        userIdFileCosService.uploadFrontFile(file, fTrueName, idNumber, request);
        return Result.success();
    }

    @PostMapping("/back/uploadFile")
    @ApiOperation(value = "上传用户身份证反面", notes = "上传用户身份证反面", httpMethod = "POST")
    @BusinessLog(title = "上传用户身份证正面")
    public Result<?> uploadBackFile(@RequestParam("file") MultipartFile file,
                                     @ApiParam(name = "fTrueName", value = "真实姓名")
                                     @RequestParam(value = "fTrueName", required = false) String fTrueName,
                                     @ApiParam(name = "idNumber", value = "身份证号")
                                     @RequestParam(value = "idNumber", required = false) String idNumber,
                                     HttpServletRequest request) {
        userIdFileCosService.uploadBackFile(file, fTrueName, idNumber, request);
        return Result.success();
    }
}
